#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        int n = nums.size(), ret = 1;
        vector<vector<int>> dp(n, vector<int>(2, 1));
        for (int i = 1; i < n; i++)
            for (int j = i - 1; j >= 0; j--)
                if (nums[i] > nums[j])
                    ret = max(ret, dp[i][1] = max(dp[i][1], 1 + dp[j][0]));
                else if (nums[i] < nums[j])
                    ret = max(ret, dp[i][0] = max(dp[i][0], 1 + dp[j][1]));
        return ret;
    }
};